/**
 * <copyright>
 * </copyright>
 *
 * $Id$
 */
package behaviourdiagram.impl;

import behaviourdiagram.Behaviour;
import behaviourdiagram.BehaviourInput;
import behaviourdiagram.BehaviourdiagramPackage;
import behaviourdiagram.Sensor;

import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.NotificationChain;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.InternalEObject;

import org.eclipse.emf.ecore.impl.ENotificationImpl;

import org.eclipse.emf.ecore.impl.EObjectImpl;
import org.eclipse.emf.ecore.util.EcoreUtil;

/**
 * <!-- begin-user-doc -->
 * An implementation of the model object '<em><b>Behaviour Input</b></em>'.
 * <!-- end-user-doc -->
 * <p>
 * The following features are implemented:
 * <ul>
 *   <li>{@link behaviourdiagram.impl.BehaviourInputImpl#getName <em>Name</em>}</li>
 *   <li>{@link behaviourdiagram.impl.BehaviourInputImpl#getSensor <em>Sensor</em>}</li>
 *   <li>{@link behaviourdiagram.impl.BehaviourInputImpl#getBehaviour <em>Behaviour</em>}</li>
 * </ul>
 * </p>
 *
 * @generated
 */
public class BehaviourInputImpl extends EObjectImpl implements BehaviourInput {
	/**
   * The default value of the '{@link #getName() <em>Name</em>}' attribute.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getName()
   * @generated
   * @ordered
   */
	protected static final String NAME_EDEFAULT = null;

	/**
   * The cached value of the '{@link #getName() <em>Name</em>}' attribute.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getName()
   * @generated
   * @ordered
   */
	protected String name = NAME_EDEFAULT;

	/**
   * The cached value of the '{@link #getSensor() <em>Sensor</em>}' reference.
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @see #getSensor()
   * @generated
   * @ordered
   */
	protected Sensor sensor;

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	protected BehaviourInputImpl() {
    super();
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	protected EClass eStaticClass() {
    return BehaviourdiagramPackage.Literals.BEHAVIOUR_INPUT;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public String getName() {
    return name;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public void setName(String newName) {
    String oldName = name;
    name = newName;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, BehaviourdiagramPackage.BEHAVIOUR_INPUT__NAME, oldName, name));
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public Sensor getSensor() {
    if (sensor != null && sensor.eIsProxy())
    {
      InternalEObject oldSensor = (InternalEObject)sensor;
      sensor = (Sensor)eResolveProxy(oldSensor);
      if (sensor != oldSensor)
      {
        if (eNotificationRequired())
          eNotify(new ENotificationImpl(this, Notification.RESOLVE, BehaviourdiagramPackage.BEHAVIOUR_INPUT__SENSOR, oldSensor, sensor));
      }
    }
    return sensor;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public Sensor basicGetSensor() {
    return sensor;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public NotificationChain basicSetSensor(Sensor newSensor, NotificationChain msgs) {
    Sensor oldSensor = sensor;
    sensor = newSensor;
    if (eNotificationRequired())
    {
      ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, BehaviourdiagramPackage.BEHAVIOUR_INPUT__SENSOR, oldSensor, newSensor);
      if (msgs == null) msgs = notification; else msgs.add(notification);
    }
    return msgs;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public void setSensor(Sensor newSensor) {
    if (newSensor != sensor)
    {
      NotificationChain msgs = null;
      if (sensor != null)
        msgs = ((InternalEObject)sensor).eInverseRemove(this, BehaviourdiagramPackage.SENSOR__INPUT, Sensor.class, msgs);
      if (newSensor != null)
        msgs = ((InternalEObject)newSensor).eInverseAdd(this, BehaviourdiagramPackage.SENSOR__INPUT, Sensor.class, msgs);
      msgs = basicSetSensor(newSensor, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, BehaviourdiagramPackage.BEHAVIOUR_INPUT__SENSOR, newSensor, newSensor));
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public Behaviour getBehaviour() {
    if (eContainerFeatureID() != BehaviourdiagramPackage.BEHAVIOUR_INPUT__BEHAVIOUR) return null;
    return (Behaviour)eContainer();
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public NotificationChain basicSetBehaviour(Behaviour newBehaviour, NotificationChain msgs) {
    msgs = eBasicSetContainer((InternalEObject)newBehaviour, BehaviourdiagramPackage.BEHAVIOUR_INPUT__BEHAVIOUR, msgs);
    return msgs;
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	public void setBehaviour(Behaviour newBehaviour) {
    if (newBehaviour != eInternalContainer() || (eContainerFeatureID() != BehaviourdiagramPackage.BEHAVIOUR_INPUT__BEHAVIOUR && newBehaviour != null))
    {
      if (EcoreUtil.isAncestor(this, newBehaviour))
        throw new IllegalArgumentException("Recursive containment not allowed for " + toString());
      NotificationChain msgs = null;
      if (eInternalContainer() != null)
        msgs = eBasicRemoveFromContainer(msgs);
      if (newBehaviour != null)
        msgs = ((InternalEObject)newBehaviour).eInverseAdd(this, BehaviourdiagramPackage.BEHAVIOUR__INPUTS, Behaviour.class, msgs);
      msgs = basicSetBehaviour(newBehaviour, msgs);
      if (msgs != null) msgs.dispatch();
    }
    else if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, BehaviourdiagramPackage.BEHAVIOUR_INPUT__BEHAVIOUR, newBehaviour, newBehaviour));
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public NotificationChain eInverseAdd(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
    switch (featureID)
    {
      case BehaviourdiagramPackage.BEHAVIOUR_INPUT__SENSOR:
        if (sensor != null)
          msgs = ((InternalEObject)sensor).eInverseRemove(this, BehaviourdiagramPackage.SENSOR__INPUT, Sensor.class, msgs);
        return basicSetSensor((Sensor)otherEnd, msgs);
      case BehaviourdiagramPackage.BEHAVIOUR_INPUT__BEHAVIOUR:
        if (eInternalContainer() != null)
          msgs = eBasicRemoveFromContainer(msgs);
        return basicSetBehaviour((Behaviour)otherEnd, msgs);
    }
    return super.eInverseAdd(otherEnd, featureID, msgs);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public NotificationChain eInverseRemove(InternalEObject otherEnd, int featureID, NotificationChain msgs) {
    switch (featureID)
    {
      case BehaviourdiagramPackage.BEHAVIOUR_INPUT__SENSOR:
        return basicSetSensor(null, msgs);
      case BehaviourdiagramPackage.BEHAVIOUR_INPUT__BEHAVIOUR:
        return basicSetBehaviour(null, msgs);
    }
    return super.eInverseRemove(otherEnd, featureID, msgs);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public NotificationChain eBasicRemoveFromContainerFeature(NotificationChain msgs) {
    switch (eContainerFeatureID())
    {
      case BehaviourdiagramPackage.BEHAVIOUR_INPUT__BEHAVIOUR:
        return eInternalContainer().eInverseRemove(this, BehaviourdiagramPackage.BEHAVIOUR__INPUTS, Behaviour.class, msgs);
    }
    return super.eBasicRemoveFromContainerFeature(msgs);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public Object eGet(int featureID, boolean resolve, boolean coreType) {
    switch (featureID)
    {
      case BehaviourdiagramPackage.BEHAVIOUR_INPUT__NAME:
        return getName();
      case BehaviourdiagramPackage.BEHAVIOUR_INPUT__SENSOR:
        if (resolve) return getSensor();
        return basicGetSensor();
      case BehaviourdiagramPackage.BEHAVIOUR_INPUT__BEHAVIOUR:
        return getBehaviour();
    }
    return super.eGet(featureID, resolve, coreType);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public void eSet(int featureID, Object newValue) {
    switch (featureID)
    {
      case BehaviourdiagramPackage.BEHAVIOUR_INPUT__NAME:
        setName((String)newValue);
        return;
      case BehaviourdiagramPackage.BEHAVIOUR_INPUT__SENSOR:
        setSensor((Sensor)newValue);
        return;
      case BehaviourdiagramPackage.BEHAVIOUR_INPUT__BEHAVIOUR:
        setBehaviour((Behaviour)newValue);
        return;
    }
    super.eSet(featureID, newValue);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public void eUnset(int featureID) {
    switch (featureID)
    {
      case BehaviourdiagramPackage.BEHAVIOUR_INPUT__NAME:
        setName(NAME_EDEFAULT);
        return;
      case BehaviourdiagramPackage.BEHAVIOUR_INPUT__SENSOR:
        setSensor((Sensor)null);
        return;
      case BehaviourdiagramPackage.BEHAVIOUR_INPUT__BEHAVIOUR:
        setBehaviour((Behaviour)null);
        return;
    }
    super.eUnset(featureID);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public boolean eIsSet(int featureID) {
    switch (featureID)
    {
      case BehaviourdiagramPackage.BEHAVIOUR_INPUT__NAME:
        return NAME_EDEFAULT == null ? name != null : !NAME_EDEFAULT.equals(name);
      case BehaviourdiagramPackage.BEHAVIOUR_INPUT__SENSOR:
        return sensor != null;
      case BehaviourdiagramPackage.BEHAVIOUR_INPUT__BEHAVIOUR:
        return getBehaviour() != null;
    }
    return super.eIsSet(featureID);
  }

	/**
   * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
   * @generated
   */
	@Override
	public String toString() {
    if (eIsProxy()) return super.toString();

    StringBuffer result = new StringBuffer(super.toString());
    result.append(" (name: ");
    result.append(name);
    result.append(')');
    return result.toString();
  }

} //BehaviourInputImpl
